package com.cdy.demo.algorithm;

import java.util.Arrays;
import java.util.Comparator;

public class Leetcode452 {

    public static void main(String[] args) {
    }

    public int findMinArrowShots(int[][] points) {
        if (points.length == 0) {
            return 0;
        }
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] point1, int[] point2) {
                if (point1[1] > point2[1]) {
                    return 1;
                } else if (point1[1] < point2[1]) {
                    return -1;
                } else {
                    return 0;
                }
            }
        });

        int num=1;
        int right = 0;
        for (int i = 1; i < points.length; i++) {
            if (points[right][1] >= points[i][0]) {
                continue;
            } else {
                right = i;
                num++;
            }
        }
        return num;
    }
}
